package cc.verywell.pureblock.msg.nfs.hd;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;

import cc.verywell.pureblock.func.node.KeyShell;
import cc.verywell.pureblock.msg.nfs.idx.NfsidxStructure;

/**
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年10月3日 下午8:24:47
*/
public interface LfsHdSupply {

	NfsidxStructure putAndHoldInternal(Object hold,KeyShell key,byte[] value) throws IOException,NoEnoughSpaceException; //idxIfhave用来对比数据版本
	void removeHold(Object hold);

	void putTemp(KeyShell key,byte[] value) throws IOException,NoEnoughSpaceException;
	
	byte[] read(NfsidxStructure idx) throws IOException;
	int read(NfsidxStructure idx,ByteBuffer bb) throws IOException;
	int read(NfsidxStructure idx,ByteBuffer bb,int offset,int length) throws IOException;
	
	final String[] SIZE_MARK = {"b","k","M","G","Tb","Eb","zB"};
	public static String formatSize(long size) {
		StringBuffer sb = new StringBuffer();
		if(size==0) {
			sb.append(0).append(SIZE_MARK[0]);
		}else if(size<0) {
			sb.append('-');
			size = 0-size;
		}
		int first = 0;
		for (int i = SIZE_MARK.length-1; i >= 0; i--) {
			long temp = (size&(-1L<<(10*i)));
			if(temp!=0) {
				if(1==first)sb.append('.');
				first++;
				size ^= temp;
				sb.append(temp>>>(10*i)).append(SIZE_MARK[i]);
			}
		}
		return sb.toString();
	}
	
}
